home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0038_How to Populate a TDBComboBox Or TDBList.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.0 KB  |  58 lines

  1.  
  2. Filling dblistboxs and dbcomboboxs
  3.  
  4. Most of Delphi's data aware components will  populate 
  5. themselves after they are wired up to a open dataset.  However 
  6. DbListboxs and DbComboboxs do not display this characteristic.  
  7. These two components are not for displaying your datasets, but 
  8. filling them.  Use of these components is straight forward.  
  9. When you update your table, the value of the DbListbox or 
  10. DbCombobox will be posted in the appropriate field.
  11.  
  12. Filling the DbCombobox or DbListbox the same as filling normal 
  13. comboboxs or listboxes.  The lines of text in a listbox or 
  14. combobox are really a tstring list.  The "Items" property of 
  15. the given component holds this list.  Use the "Add" method for 
  16. adding items to a tstring. If you want to use data  types other 
  17. than strings they must be converted at run time. If your list 
  18. has a blank line at the end, consider setting the 
  19. "IntegralHeight" property to True.
  20.  
  21.  
  22. Filling a DbListbox with 4 lines programmatically might look 
  23. similar to this:
  24.  
  25.      DbListbox1.items.add('line one');
  26.      DbListbox1.items.add('line two');
  27.      DbListbox1.items.add('line three');
  28.      DbListbox1.items.add('line four');
  29.  
  30. Filling a DbListbox at design time requires using the object 
  31. inspector.  By double clicking on the components "Items" 
  32. property, you can bring up the "String List Editor" and input 
  33. the desired rows.
  34.  
  35. Unfortunately, if a combobox is filled this way, there is not 
  36. default value.  Setting a DbComboboxs "text" property will 
  37. achieve this result.  (the "text" property is not available in 
  38. the object inspector, so it must be set programmatically).
  39. Setting the default value to the first value in the
  40. DbCombobox's list looks like this:
  41.  
  42. DbCombobox1.text := DbCombobox1.items[0];
  43.  
  44. Often it is useful to fill a DBListBox from a dataset.  This 
  45. can be done using loop:
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. begin
  49.   with table2 do begin
  50.     open;
  51.     while not EOF do
  52.     begin
  53.       DBlistbox1.items.add(FieldByName('name').AsString); 
  54.       next;
  55.     end;
  56.   end;
  57. end;
  58.